package com.afkt.project.ui.slice;

import com.afkt.project.base.app.BaseActivity;
import com.ohos.afkt.ResourceTable;
import com.dev.utils.app.BarUtils;
import ohos.aafwk.content.Intent;
import ohos.agp.colors.RgbColor;
import ohos.agp.components.*;
import ohos.agp.components.element.ShapeElement;
import ohos.global.resource.NotExistException;
import ohos.global.resource.WrongTypeException;

import java.io.IOException;

public class StatusBarSlice extends BaseActivity {

    // 判断是否显示
    private boolean display = false;

    private DirectionalLayout bar_Layout;
    private DirectionalLayout bar;
    private Image select_retuen;

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        bar_Layout = (DirectionalLayout) findComponentById(ResourceTable.Id_base_view_barLayout);
        bar = (DirectionalLayout) LayoutScatter.getInstance(this).parse(ResourceTable.Layout_sheet_dialog_bar, null, false);
        Text text = (Text) bar.findComponentById(ResourceTable.Id_titleText);
        select_retuen = (Image) bar.findComponentById(ResourceTable.Id_sheet_dialog_return);
        text.setText("点击显示隐藏（状态栏）");
        bar_Layout.addComponent(bar);

        DirectionalLayout.LayoutConfig layoutConfig =
                new DirectionalLayout.LayoutConfig(ComponentContainer.LayoutConfig.MATCH_PARENT,
                        BarUtils.getStatusBarHeight());
        int color = 0;
        ohos.global.resource.ResourceManager resManager = getContext().getResourceManager();
        try {
            color = resManager.getElement(ResourceTable.Color_colorPrimary).getColor();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (NotExistException e) {
            e.printStackTrace();
        } catch (WrongTypeException e) {
            e.printStackTrace();
        }
        Component statusView = new Component(getContext());
        ShapeElement shapeElement = new ShapeElement();

        shapeElement.setRgbColor(RgbColor.fromArgbInt(color));
        statusView.setBackground(shapeElement);
        statusView.setLayoutConfig(layoutConfig);

        Button btn  = (Button) findComponentById(ResourceTable.Id_vid_asb_toggle_btn);
        btn.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                BarUtils.setStatusBarVisibility(getAbility(), display);
                display = !display;
            }
        });
    }

    @Override
    protected int baseLayoutId() {
        return ResourceTable.Layout_activity_status_bar;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initListener() {
        select_retuen.setClickedListener(component -> {
           // LogUtils.error(TAG, "return 点击");
            onBackPressed();
        });
    }

    @Override
    protected void onBackground() {
        super.onBackground();
        bar_Layout.removeAllComponents();
    }
}
